﻿#region Copyright(c) 2006 ZO, All right reserved.
// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1.  Redistribution of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//   2.  Redistribution in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//   3.  The name of the author may not be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
#endregion


#region Using directives

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO.Ports;

#endregion

namespace ZO.SmartCore.My4CSharp
{
    /// <summary>Provides a property and a method for accessing the computer's serial ports.</summary>
    [Browsable(false)]
    [EditorBrowsable(EditorBrowsableState.Advanced)]
    public class Ports
    {

        #region Constructors

        #endregion

        #region Destructor

        #endregion

        #region Fields

        #endregion

        #region Events

        #endregion

        #region Operators

        #endregion

        #region Properties
        /// <summary>Gets a collection of the names of the serial ports on the computer.</summary>
        /// <returns>A collection of the names of the serial ports on the computer.</returns>
        public ReadOnlyCollection<string> SerialPortNames
        {
            get
            {
                string[] textArray1 = SerialPort.GetPortNames();
                List<string> list1 = new List<string>();
                foreach (string text1 in textArray1)
                {
                    list1.Add(text1);
                }
                return new ReadOnlyCollection<string>(list1);
            }
        }
 

        #endregion

        #region Methods
        /// <summary>Creates and opens a <see cref="T:System.IO.Ports.SerialPort"></see> object.</summary>
        /// <returns>An open <see cref="T:System.IO.Ports.SerialPort"></see> object, configured with the supplied arguments.</returns>
        /// <param name="portName">String. Required. Name of the port to open.</param>
        /// <PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /></PermissionSet>
        public SerialPort OpenSerialPort(string portName)
        {
            SerialPort port2 = new SerialPort(portName);
            port2.Open();
            return port2;
        }

        /// <summary>Creates and opens a <see cref="T:System.IO.Ports.SerialPort"></see> object.</summary>
        /// <returns>An open <see cref="T:System.IO.Ports.SerialPort"></see> object, configured with the supplied arguments.</returns>
        /// <param name="baudRate">Integer. Baud rate of the port.</param>
        /// <param name="portName">String. Required. Name of the port to open.</param>
        /// <PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /></PermissionSet>
        public SerialPort OpenSerialPort(string portName, int baudRate)
        {
            SerialPort port2 = new SerialPort(portName, baudRate);
            port2.Open();
            return port2;
        }


        /// <summary>Creates and opens a <see cref="T:System.IO.Ports.SerialPort"></see> object.</summary>
        /// <returns>An open <see cref="T:System.IO.Ports.SerialPort"></see> object, configured with the supplied arguments.</returns>
        /// <param name="baudRate">Integer. Baud rate of the port.</param>
        /// <param name="portName">String. Required. Name of the port to open.</param>
        /// <param name="parity"><see cref="T:System.IO.Ports.Parity"></see>. Parity of the port.</param>
        /// <PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /></PermissionSet>
        public SerialPort OpenSerialPort(string portName, int baudRate, Parity parity)
        {
            SerialPort port2 = new SerialPort(portName, baudRate, parity);
            port2.Open();
            return port2;
        }


        /// <summary>Creates and opens a <see cref="T:System.IO.Ports.SerialPort"></see> object.</summary>
        /// <returns>An open <see cref="T:System.IO.Ports.SerialPort"></see> object, configured with the supplied arguments.</returns>
        /// <param name="baudRate">Integer. Baud rate of the port.</param>
        /// <param name="portName">String. Required. Name of the port to open.</param>
        /// <param name="dataBits">Integer. Data-bit setting of the port.</param>
        /// <param name="parity"><see cref="T:System.IO.Ports.Parity"></see>. Parity of the port.</param>
        /// <PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /></PermissionSet>
        public SerialPort OpenSerialPort(string portName, int baudRate, Parity parity, int dataBits)
        {
            SerialPort port2 = new SerialPort(portName, baudRate, parity, dataBits);
            port2.Open();
            return port2;
        }


        /// <summary>Creates and opens a <see cref="T:System.IO.Ports.SerialPort"></see> object.</summary>
        /// <returns>An open <see cref="T:System.IO.Ports.SerialPort"></see> object, configured with the supplied arguments.</returns>
        /// <param name="baudRate">Integer. Baud rate of the port.</param>
        /// <param name="portName">String. Required. Name of the port to open.</param>
        /// <param name="dataBits">Integer. Data-bit setting of the port.</param>
        /// <param name="parity"><see cref="T:System.IO.Ports.Parity"></see>. Parity of the port.</param>
        /// <param name="stopBits"><see cref="T:System.IO.Ports.StopBits"></see>. Stop-bit setting of the port.</param>
        /// <PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" PathDiscovery="*AllFiles*" /></PermissionSet>
        public SerialPort OpenSerialPort(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits)
        {
            SerialPort port2 = new SerialPort(portName, baudRate, parity, dataBits, stopBits);
            port2.Open();
            return port2;
        }

 


        #endregion
    }
}
